<!--
 * @Author: hl
 * @Date: 2023-07-11 13:52:31
 * @LastEditors: lh
 * @LastEditTime: 2023-10-12 14:34:02
-->
<template>
  <div>
    <!-- :searchDataList="searchDataListJy" -->
    <tabCom
      @Refresh="Refresh"
      @search-callback="searchCallback"
      :title="'已办事项'"
      :operation-api="operationApiA"
      :table-data-rule="tableDataRuleA"
      :search-data-list="searchDataListJy"
      :needPagination="true"
      :update_show_key="'id'"
      :update_show_value="[0]"
      :formDataWidth="'30%'"
      :isShowDownLoadFile="false"
      :updateShow="false"
      :isShowAddBtn="false"
      :mustSearchData="{ processState: 2 }"
    >
      <template #add="{ formData }">
        <el-form-item :label="item.title" v-for="(item, index) in searchDataListJyEdit" :key="index">
          <el-input v-if="!item.type" v-model="formData[item.name]" placeholder="请输入" />
          <el-input
            v-else-if="item.type == 'number'"
            type="number"
            v-model="formData[item.name]"
            placeholder="请输入"
          />
          <!-- value-format="YYYY/MM/DD" -->
          <el-date-picker
            v-else-if="item.type == 'timeday'"
            v-model="formData[item.name]"
            type="date"
            format="YYYY/MM/DD"
            placeholder="请选择"
          />
          <el-date-picker
            v-else-if="item.type == 'datetime'"
            v-model="formData[item.name]"
            type="datetime"
            format="YYYY/MM/DD HH:mm:ss"
            placeholder="请选择"
          />
          <upfilebox
            v-else-if="item.type == 'file'"
            fileType="file"
            v-model="formData[item.name]"
            v-model:name="formData[item.prop]"
          ></upfilebox>
          <el-date-picker
            @change="chooseTimeChange(formData[item.name])"
            v-else-if="item.type == 'time'"
            v-model="formData[item.name]"
            type="datetimerange"
            format="YYYY/MM/DD"
            value-format="YYYYMMDD"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
          <el-select
            v-else-if="item.type == 'select' && item!.list!.length > 0"
            v-model="formData[item.name]"
            default-first-option
            :reserve-keyword="false"
            clearable
            allow-create
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="items in item.list"
              :key="items.value"
              :label="items.label || items.name"
              :value="items.value || items.id"
            />
          </el-select>
          <el-select
            v-else-if="item.type == 'selectLable'"
            v-model="formData[item.name]"
            default-first-option
            :reserve-keyword="false"
            clearable
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="items in item.list"
              :key="items.value"
              :label="items.label || items.name"
              :value="items.label || items.name"
            />
          </el-select>
          <el-select
            v-else-if="item.type == 'multipleSelect'"
            multiple
            v-model="formData[item.name]"
            default-first-option
            :reserve-keyword="false"
            clearable
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="items in item.list"
              :key="items.value"
              :label="items.label || items.name"
              :value="items.label || items.name"
            />
          </el-select>
        </el-form-item>
      </template>
    </tabCom>
  </div>
</template>
<script lang="ts" setup>
import tabCom from "@/components/table/indexcopy.vue"
// import { gethomeStatistics } from "@/api/home/index"
import { ref, onMounted } from "vue"
import upfilebox from "@/components/table/upfile.vue"

onMounted(() => {
  init()
})
// 时间选择限定范围
const chooseTimeChange = (time: any) => {
  const starTime = JSON.parse(JSON.stringify(time[0]))
  const endTime = JSON.parse(JSON.stringify(time[1]))
  const minTime = new Date(insertStr(insertStr(starTime, 4, "-"), 7, "-")).getTime()
  const maxTime = new Date(insertStr(insertStr(endTime, 4, "-"), 7, "-")).getTime()
  const allow = 2592000000 //30天
  if (maxTime - minTime > allow) {
    ElMessage.warning("选择范围请在30天以内!")
    chaxunState.value = false
  } else {
    chaxunState.value = true
  }
}
// 接口请求配置
const operationApiA = ref<any>([
  { type: "add", interface: "/dangerousWork/insertOrUpdate" },
  { type: "update", interface: "/dangerousWork/insertOrUpdate" },
  { type: "search", interface: "/processMatter/selectAll" },
  { type: "delete", interface: "/dangerousWork/deleteByIds" }
])

// 搜索配置
const searchDataListJy = [
  { name: "id", title: "id" },
  { name: "number", title: "编号" },
  { name: "title", title: "标题" },
  { name: "startTime", title: "开始时间", type: "datetime" },
  { name: "endTime", title: "结束时间", type: "datetime" }
]
// 添加配置
const searchDataListJyEdit = [
  { name: "constructionActivities", title: "施工活动" },
  { name: "constructionUnit", title: "施工单位" },
  { name: "programmeName", title: "方案名称	" },
  { name: "programmeNum", title: "方案编号" },
  { name: "scale", title: "规模" },
  {
    name: "constructionProgress",
    title: "施工进展",
    type: "select",
    list: [
      { value: 0, label: "未开始", name: "未开始", id: 0 },
      { value: 1, label: "施工中", name: "施工中", id: 1 },
      { value: 2, label: "已完成", name: "已完成", id: 2 }
    ]
  },
  { name: "supervisionImplementationRulesUrl", title: "监理实施细则", type: "file" },
  { name: "specialConstructionPlanReviewRecordUrl", title: "专项施工方案审查记录", type: "file" },
  { name: "specialInspectionRecordUrl", title: "专项巡视检查记录", type: "file" },
  { name: "acceptanceDataUrl", title: "验收资料", type: "file", props: "acceptanceDataName" },
  { name: "rectificationDataUrl", title: "整改资料", type: "file", props: "rectificationDataName" },
  { name: "responsible", title: "责任人" },
  { name: "remarks", title: "备注" }
]
// 表单配置
const tableDataRuleA = ref([
  { prop: "id", label: "id" },
  { prop: "title", label: "标题" },
  { prop: "number", label: "编号" },
  { prop: "sourceModule", label: "来源模块	" },
  { prop: "programmeNum", label: "方案编号" },
  { prop: "scale", label: "规模" },
  {
    prop: "processState",
    label: "流程状态",
    type: "select",
    list: [
      { value: 1, label: "待办事项", name: "待办事项", id: 1 },
      { value: 2, label: "已办事项", name: "已办事项", id: 2 }
    ]
  },
  { prop: "createTime", label: "创建时间", type: "time" },
  { prop: "initiateUser", label: "发起人" },
  { prop: "remarks", label: "备注" }
  // {prop: 'operate',label: '操作'},
])
// 初始化
const init = () => {}
// 表单刷新
const Refresh = () => {
  //用户数据概览
}
// 搜索回调
const searchCallback = (search: any) => {}
const loading = ref<boolean>(false)
const gailan = ref<any>({})
const gethomeStatisticsStar = (obj: any = {}) => {
  // loading.value = true
  // gethomeStatistics(obj).then((res: any) => {
  //   gailan.value = res.data
  //   loading.value = false
  // })
}
</script>
<style scoped lang="scss">
.search-wrapper {
  margin: 0 auto;
  width: 98.5%;
  margin-top: 10px;
}
</style>
